/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.cx1.service.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import org.cx1.model.Inquiry;
import org.cx1.model.Lead;
import org.cx1.model.ds.MockDS;
import org.cx1.model.utils.ServiceResponse;
import org.cx1.service.api.ILeadService;
import org.cx1.service.utils.IDGenerator;

/**
 *
 * @author ECH
 */
public class MLeadService implements ILeadService {
    
    @Override
    public ServiceResponse<String> create(String name, String email, String description) {
        ServiceResponse<String> response = new ServiceResponse<String>();
        String id = null;        
        try {            
            Lead entry = new Lead();
            id = IDGenerator.generateID();
            
            entry.setId(id);      
            
            entry.setName(name);
            entry.setEmail(email);
            entry.setDescription(description);
                        
            entry.setActive(true);
            entry.setDateCreated(new Date());
            entry.setDateModified(new Date());
                        
            MockDS.getLeads().add(entry);
            
            response.setResponse(id);
            response.setSuccessful(true);            
        } 
        catch (Exception ex) {
            response.setResponse(null);
            response.setSuccessful(false);
            response.setMessage(ex.getMessage());
            response.setException(ex);
            ex.printStackTrace();            
        }
        return response; 
    }

    @Override
    public ServiceResponse<List<Lead>> readAll(int offset, int limit) {
        ServiceResponse<List<Lead>> response = new ServiceResponse<List<Lead>>();
        List<Lead> leads = new ArrayList<Lead>();
        try {            
            List<Lead> records = MockDS.getLeads();
            if (records != null && records.size() > 0) {
                if (offset == 0 && limit == 0) {
                    leads.addAll(records);
                }
                else if (offset < records.size() && limit < records.size()) {
                    leads.addAll(records);
                }              
            }            
                      
            response.setResponse(leads);
            response.setSuccessful(true);            
        } 
        catch (Exception ex) {
            response.setResponse(null);
            response.setSuccessful(false);
            response.setMessage(ex.getMessage());
            response.setException(ex);
            ex.printStackTrace();            
        }
        return response; 
    }

    @Override
    public ServiceResponse<String> create(Lead lead) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public ServiceResponse<Boolean> delete(String id) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }
    
}
